package com.larly.service.impl;

import cn.hutool.core.util.ObjUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.larly.exception.ErrorCode;
import com.larly.exception.ThrowUtils;
import com.larly.model.domain.NoteVersions;
import com.larly.model.vo.NotesVO;
import com.larly.service.NoteVersionsService;
import com.larly.mapper.NoteVersionsMapper;
import com.larly.service.NotesService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
* @author 许颢达
* @description 针对表【note_versions(记录笔记的历史编辑版本，note_id用于关联笔记但无强制外键约束)】的数据库操作Service实现
* @createDate 2025-08-19 15:26:06
*/
@Service
public class NoteVersionsServiceImpl extends ServiceImpl<NoteVersionsMapper, NoteVersions>
    implements NoteVersionsService{

    @Resource
    private NotesService notesService;


    /**
     * 根据id获取笔记历史版本
     * @param id
     * @return
     */
    @Override
    public NotesVO getNoteVersionsById(Integer id) {
        ThrowUtils.throwIf(ObjUtil.isEmpty(id), ErrorCode.PARAM_ERROR, "笔记历史版本ID不能为空");
        NoteVersions noteVersions = this.getById(id);
        if (noteVersions != null) {
            return NotesVO.toVO(notesService.getById(noteVersions.getNoteId()));
        }
        return null;
    }
}




